package com.sneaker.shower.controller;

import com.sneaker.shower.common.BaseView;
import com.sneaker.shower.entity.dto.coupon.CouponCreateDTO;
import com.sneaker.shower.entity.dto.coupon.CouponDTO;
import com.sneaker.shower.service.CouponService;
import com.sneaker.shower.util.JacksonUtils;
import io.swagger.annotations.ApiModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Hechangjian
 * @version 1.0
 * @className CouponController
 * @date 2019/11/26 11:51
 * @description 优惠券接口
 * @program bath
 */
@RestController
@Slf4j
@ApiModel("优惠券接口")
@RequestMapping("/coupon")
public class CouponController {

    private final CouponService couponService;

    @Autowired
    public CouponController(CouponService couponService) {
        this.couponService = couponService;
    }

    @PostMapping("/create_coupon")
    public BaseView<List<CouponDTO>> createCoupon(@RequestBody CouponCreateDTO couponCreateDTO) {
        log.info("创建优惠券请求入参：【{}】", JacksonUtils.writeValueAsString(couponCreateDTO));
        return new BaseView<>(couponService.createCoupon(couponCreateDTO));
    }

    @GetMapping("/disabled_all")
    public BaseView<String> disabledCoupon() {
        log.info("禁用所有优惠券请求");
        return new BaseView<>(couponService.disableAll());
    }
}
